#ifndef _CONSOLE_H_
#define _CONSOLE_H_

#include <string>
#include "input/keyboard.h"
#include "math/vec2.h"

namespace LuaPlus
{
    class LuaState;
}  // namespace LuaPlus

class Image;
class Font;

namespace console
{

class Console : public input::KeyboardListener
{
public:
    static Console&			Instance();
	void					Init(const std::string& ConsoleFile, const std::string& ConsoleFont = "");
	void					Shutdown();
	/// add to output data
	void					Output(const std::string&	Text);
	/// Execute a string

	void					Do(const std::string&	Script);
	void					DoEx(const char*  _Msg, ...);

	/// Enable/disable auto command Output
	void					PrintLastCommand(bool b = true)	{ m_PrintLastCmd = b; }

    /**
     *  Allow a script state to share the Console LUABind functionality
     *  @param  _pScript   Script to register in
     */
     static void           Register(LuaPlus::LuaState* _pScript);

	 /// draw visually
	 void					Render();
	/// log a message from stream
	 static int				LogMessage( const char * str );
	/// retrieve the Script state
 	LuaPlus::LuaState*	GetScript() const { return m_pScriptState; };

	// luabind insists on having a destructor for this
	 ~Console();
	bool					GetClipBoard(std::string& Buffer);

	void					BindKey(unsigned long KeyID, const std::string& Script);

	void					ForceDisabled(bool Disable);

	bool					IsActive() const { return m_IsActive; };

//	void					SetFont(const std::string& Face, int Width, int Height, bool Italic, int Weight);
//	void					SetFont(Font* pFont);

	void					SetBackground(const std::string& File);
private:
	struct	BoundKey
	{
		unsigned long		KeyID;
		std::string			Script;
	};

	// key pressed
	virtual	void			KeyPressed(input::Keyboard::KEY* pKey);
	virtual void			CharReceived(unsigned int Key);
	
							Console();
    /// Not implemented to prevent copying
    Console( const Console & );     
    Console& operator=( const Console & );
	
//	Font*				m_pFont;

	/// is the console active?
	bool					m_IsActive;
	bool					m_ForceDisabled;
	bool					m_PrintLastCmd;
	/// background image
	Image*					m_pBackground;
	/// output strings
	std::vector<std::string>m_Output;
	/// input text
	std::string				m_Input;
	/// Script state
	LuaPlus::LuaState*		m_pScriptState;
	/// File the script was loaded from
	std::string				m_FileName;

	float					m_PromptPos;
	float					m_BackgroundHeight;
	float					m_TextHeight;

	unsigned int			m_PromptIndex;
	std::vector<std::string>	m_PromptList;
	std::vector<BoundKey>	m_BoundKeys;
};

};

#endif // _CONSOLE_H_